package com.example.healing.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.healing.common.lang.Result;
import com.example.healing.entity.ListSong;
import com.example.healing.mapper.ListSongMapper;
import com.example.healing.service.ListSongService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author neymar
 * @date 2021年11月30日 15:34
 */
@Service
public class ListSongImpl extends ServiceImpl<ListSongMapper, ListSong> implements ListSongService {

    @Autowired
    private ListSongMapper listSongMapper;

    @Override
    public Result create(ListSong song) {
        int res =  listSongMapper.insert(song);
        return res == -1 ? Result.fail("添加至歌单失败") : Result.succ("成功添加至歌单");
    }

    @Override
    public Result delete(ListSong song) {
        String listId = song.getListId();
        String songId = song.getSongId();
        QueryWrapper<ListSong> songQuery = new QueryWrapper<ListSong>().eq("listId",listId).eq("songId",songId);
        int res = listSongMapper.delete(songQuery);
        return res == 0 ? Result.fail("歌曲移除失败") : Result.succ("歌曲移除失败");
    }

    @Override
    public Result edit(ListSong song) {
        // TODO: 2021/12/1 暂时不需要 留空
        return null;
    }

    /**
     * @author neymar
     * @date 2021/12/1 22:21
     * @param listId
     * @return com.example.healing.common.lang.Result
     * @description
     */
    @Override
    public Result getSongList(String listId) {
        QueryWrapper<ListSong> songsQuery = new QueryWrapper<ListSong>().eq("listId",listId);
        List<ListSong> lists = listSongMapper.selectList(songsQuery);
        int res = lists.size();
        return res > 0 ? Result.succ(lists) : Result.succ("歌单中暂未添加任何歌曲~");
    }
}
